package org.ft.web;

import com.ft.core.runtime.session.IAuthUser;
import com.ft.security.controller.BaseSecurityController;
import com.ft.core.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.ft.service.IUserService;
import org.ft.service.feign.IGaoDeFalconServiceManager;
import org.ft.service.feign.result.service.ServiceAddResult;
import org.ft.service.impl.ZHResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * @copyright (C), 2015-2019, 梵途科技有限公司
 * @fileName: SampleController
 * @author: 李阳
 * @date: 2019/4/18 9:49
 * @description:
 */
@RestController
@RequestMapping("/dept")
@Api(value = "dept", tags = "部门管理模块")
public class SampleController extends BaseSecurityController {

    @Resource
    private IUserService userService;

    @Resource
    private IGaoDeFalconServiceManager gaoDeFalconServiceManager;

    @ApiOperation(value = "查询地址位置")
    @RequestMapping(value = "/getRegeo", method = RequestMethod.GET)
    public List<ZHResult> getRegeo() {
        return userService.vitify();
    }

    @ApiOperation(value = "没设置权限", notes = "查询所有的人员接口说明")
    @RequestMapping(value = "/test4", method = RequestMethod.GET)
    public IAuthUser test4() {

        final IAuthUser user = SecurityUtils.getUser();
        //throw new UserFriendlyException("123123");
        return user;
    }

    @ApiOperation(value = "允许匿名", notes = "查询所有的人员接口说明")
    @RequestMapping(value = "/test3", method = RequestMethod.GET)
    @PreAuthorize("permitAll()")
    //@PreAuthorize("hasAuthority('SYSTEM:USER:INSERT2')")
    public IAuthUser test3() {

        final IAuthUser user = SecurityUtils.getUser();
        //throw new UserFriendlyException("123123");
        return user;
    }

    @ApiOperation(value = "错误权限", notes = "查询所有的人员接口说明")
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    //@PreAuthorize("permitAll()")
    @PreAuthorize("hasAuthority('SYSTEM:USER:INSERT2')")
    public IAuthUser test() {

        final IAuthUser user = SecurityUtils.getUser();
        //throw new UserFriendlyException("123123");
        return user;
    }

    @ApiOperation(value = "正确权限", notes = "查询所有的人员接口说明")
    @RequestMapping(value = "/test2", method = RequestMethod.GET)
    //@PreAuthorize("permitAll()")
    @PreAuthorize("hasAuthority('SYSTEM:USER:INSERT')")
    public IAuthUser test2() {

        final IAuthUser user = SecurityUtils.getUser();
        //throw new UserFriendlyException("123123");
        return user;
    }

    @ApiOperation(value = "查询所有的人员2", notes = "查询所有的人员接口说明")
    @RequestMapping(value = "/postAdd", method = RequestMethod.POST)
    @PreAuthorize("hasAuthority('SYSTEM:USER:INSERT')")
    public ServiceAddResult postAdd(@NotNull String name,
                                    String desc) {
        return gaoDeFalconServiceManager.add("7a714c7aa3b8f3e0721a051f6b17cebe", name, desc);
        //UserEntity userEntity = userService.getById(input.getId());
        //return AutoMapUtils.mapTo(UserInfoOutput.class, userEntity);
    }
}
